<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" center width="800px">
      <el-row>
        <el-col :offset="6" :span="6">
          <el-form-item label="文件类型" prop="fileType" style="width: 100%;">
            <el-select
              v-model="form.fileType"
              placeholder="文件类型"
              center
            >
              <el-option
                v-for="dict in dictMap.FILE_TYPE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :offset="6" :span="12">
          <div style="margin-bottom:20px;color:dodgerblue" onclick="">
            点击此处下载导入模板
          </div>
        </el-col>
      </el-row>

      <el-row>
        <el-col :offset="6" :span="12">
          <el-form-item label="文件目录" prop="fileName">
            <!-- <file-upload-input></file-upload-input> -->
            <ht-upload-form-item
              ref="attachmentFormItem"
              v-model="form.fileName"
              @successCallback="successCallback"
              :limit="{
                    type: ['csv'],
                  }"
              ></ht-upload-form-item>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :offset="6" :span="12">
          <el-form-item>
            <el-button type="primary" @click="submitForm">提 交</el-button>
            <el-button  @click="refresh">重 置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { blackListFileUpload} from "@/api/cnaps/bizMng/blackList.js";
import { listPageMixin } from "@/libs/listPageMixin";

export default {
  name: "blackList_FileUpload",
  mixins: [listPageMixin],
  components: {
  },
  data() {
    return {
      title: "",
      // 是否显示弹出层
      openState: false,
      // 字段可编辑控制

      //数据字典
      searchFormDictList: [
       "FILE_TYPE"
      ],
      // 表单参数
      form:{},
      // 表单校验
      rules: {
        fileType: [{ required: true, message: "请选择文件类型", trigger: "blur" }],
        fileName: [{ required: true, message: "请上传文件", trigger: "blur" }],
      },
      opButtonList: () => {
        return [
        ];
      },
    };
  },
  mounted() {
  },
  methods: {
    // 表单重置
    reset() {
      this.resetForm("form");
      this.$set(this, "form", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          this.reset();
          done();
        })
        .catch(_ => {});
    },

    successCallback(res,file,fileList) {
      console.log('fileList',fileList)
      let fileName = "";

      fileList.forEach((v) => {
              fileName = fileName + "," + v.fileOriginName;
          });

      this.$set(this.form, "fileName", fileName);
    },

    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          blackListFileUpload(this.form).then(response => {
            this.msgSuccess("录入成功");
            this.refresh();
          });
        }
      });
    },
    //点击重置按钮
    refresh(){
      this.resetForm("form");
    },
    cancel() {
      this.openState = false;
      this.reset();
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
